<template>
  <el-upload
      class="upload-demo"
      :action="'/api'+props.url"
      accept=".xlsx, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      :headers="{authorization:'Bearer '+getToken()}"
      :on-success="handleUploadSuccess"
      :on-error=" handleUploadError"
  >
    <el-button type="danger" size="small" icon="Upload">导入</el-button>
  </el-upload>
</template>

<script setup>
import {getToken} from "@/util/auth.js";
import {ElMessage} from 'element-plus'

let props = defineProps({
  url: {
    type: String,
    default: ""
  }
})

let handleUploadSuccess = (res) => {
  ElMessage({message: '上传成功！', type: 'success',})
}
let handleUploadError = (res) => {
  ElMessage({message: '上传失败！', type: 'error',})
}
</script>

<style scoped>
.upload-demo {
  display: inline;
  margin-left: 12px;
}
</style>
